{% extends "personal_center/base.html" %}

{% block page_link %}
    {#    <script src="../../static/administrative/js/car_apply_detail.js"></script>#}
    <link rel="stylesheet" href="../../static/technological/css/style.css">

{% endblock %}


{% block style %}
    <style>
        .add_class {
            background: #1E90FF;
        }
        .add_background {
            background: #A9A9A9;
        }
        tr {
            height: 35px;
        }
        td {
            padding-right: 5px;outline: none;height: 40px;
        }
        th {
            text-align: center;
        }
        .file {
            position: relative;display: inline-block;background: #D0EEFF;border: 1px solid #99D3F5;border-radius: 4px;padding: 4px 12px;overflow: hidden;color: #1E88C7;text-decoration: none;text-indent: 0;line-height: 20px;
        }
        .file input {
            position: absolute;font-size: 100px;right: 0;top: 0;opacity: 0;
        }
        .file:hover {
            background: #AADFFD;border-color: #78C3F3;color: #004974;text-decoration: none;
        }
    </style>
{% endblock %}


{% block right_content %}
    <div class="headline">
        <div style="width: 15%;height: 100%;line-height: 40px;float: left;padding-left: 1%;">
            <a href="#" style="color: #0b0b0b;">
                <i class="iconfont icon-faqi"></i>
                <a href="javascript:;" style="color: #0b0b0b;"> 新增申请</a>
            </a>
        </div>
        <div style="height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"
                    onclick="save_data()">
                保存
            </button>
        </div>

        <div style="width: 15%;height: 100%;line-height: 40px;float: right;text-align: right;padding-right: 15px;">
            <button id="add_station" type="button"
                    style="width: 100px;height: 30px;margin-top: 5px;border-radius: 3px;border: #1E90FF solid 1px;background-color: #1E90FF;color: white;line-height: 25px;"
                    onclick="submit_data()">
                提交
            </button>
        </div>
    </div>
    <hr>

    <div style="width: 100%;height: 95%;">
        <div id="menu_from"
             style="width: 100%;height: 100%;color: #2C3E50;display: inline-block;vertical-align: top;background: white;overflow: auto;">
            <div style="width: 100%;height: 90%;display: inline-block;vertical-align: center;">
                <div style="width: 95%;margin-left: 2.5%;">
                    <table style="width: 100%;margin-top: 20px;">
                        <tr>
                            <td colspan="4" style="width: 95%;margin-left: 2.5%;height: 40px;padding-left: 0.5%;line-height: 40px;border: #cfcfcf solid 1px;text-align: center;">
                                <h3 id="form_name" style="letter-spacing: 8px;">快捷用印授权</h3>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4" style="width: 95%;margin-left: 2.5%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #DFDFDF;border: #cfcfcf solid 1px;border-top: none;">基本信息</td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;letter-spacing: 2px;">
                                申&nbsp;请&nbsp;人
                            </td>
                            <td id="applicat" style="width: 40%;height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;">{{ shortcut_obj.apply_user.real_name }}</td>

                            <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                申请部门
                            </td>
                            <td id="department" style="width: 40%;border: #cfcfcf solid 0.5px;padding-left: 1%;line-height: 35px;">{{ shortcut_obj.company.name }}</td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                生效时间
                            </td>
                            <td id="take_effect_time" style="width: 30%;border: #cfcfcf solid 0.5px;padding-left: 1%;line-height: 35px;">{{ shortcut_obj.take_effect_time }}</td>
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                失效时间
                            </td>
                            <td id="lose_efficacy_time" style="width: 50%;height: 35px;line-height: 35px;padding-left: 1%;border: #cfcfcf solid 0.5px;">
                                {{ shortcut_obj.lose_efficacy_time }}
                            </td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <td style="width: 10%;border: #cfcfcf solid 0.5px;text-align: right;height: 35px;line-height: 35px;">
                                申请类型
                            </td>
                            <td id="shenqing_type" colspan="3" style="width: 20%;border: #cfcfcf solid 0.5px;padding-left: 1%;line-height: 35px;">{{ shortcut_obj.authorization_type }}</td>
                        </tr>
                    </table>
                    <table id="leimuId" style="width: 100%;">
                        <tr style="margin-left: 1%;">
                            <td colspan="5" style="width: 95%;margin-left: 2.5%;height: 40px;padding-left: 0.5%;line-height: 40px;background: #dfdfdf;border: #cfcfcf solid 1px;border-top: none;">
                                授权详情
{#                                <span style="float: right;padding-right: 10px;color: #00a0e9;cursor: pointer;" onclick="add_other()">添加</span>#}
                            </td>
                        </tr>
                        <tr style="margin-left: 1%;">
                            <th style="width: 10%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;">序号</th>
                            <th style="width: 40%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;">
                                授权印章
                            </th>
                            <th style="width: 22.5%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;">
                                授权类目
                            </th>
                            <th style="width: 22.5%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;">
                                授权级别
                            </th>
                            <th style="width: 5%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;">
                                操作
                            </th>
                        </tr>

                        {% if reason|length %}
                            {% for foo in reason %}
                                <tr style="margin-left: 1%;">
                                    <td class="leimuxuhao" style="width: 10%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;">{{ foo.xuhao }}</td>
                                    <td style="width: 40%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;">
                                        <select name="choose_seal" onchange="select_seal(1)" id="AuthorizedSeal{{ foo.xuhao }}" style="width: 100%;height: 100%;border: none;outline: none;">
                                            {% for seal in seal_obj %}
                                                <option value="{{ seal.id }}" {% if foo.yinzhang == seal.id %} selected {% endif %} style="text-align: center;">{{ seal.seal_name }}</option>
                                            {% endfor %}
                                        </select>
                                    </td>
                                    <td class="leimuneirong" style="width: 22.5%;border: #cfcfcf solid 0.5px;height: 35px;line-height: 35px;padding-left: 0.5%;text-align: center;">
                                        <select name="" class="span_tag" id="span_{{ foo.xuhao }}" style="width: 100%;height: 100%;border: none;outline: none;" onchange="seleect_subject(this.id)">
                                            <option value="0" style="text-align: center;">请选择授权印章</option>
                                            {% for f in quick_obj %}
                                                {% if foo.yinzhang == f.yinzhang %}
                                                    {% for j in f.neirong %}
                                                        <option value="{{ j.neirong }}" {% if foo.neirong == j.neirong %} selected {% endif %}>{{ j.neirong }}</option>
                                                    {% endfor %}
                                                {% endif %}
                                            {% endfor %}
                                        </select>
                                    </td>
                                    <td class="shouquan_leval" style="width: 22.5%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;cursor: pointer;">
                                        {{ foo.leval }}
                                    </td>
                                    <td style="width: 5%;border: #cfcfcf solid 0.5px;cursor: pointer;text-align: center;">
                                        <span onclick="remove_time_adress(this)" style="color: red; cursor: pointer; display: inline-block;">删除</span>
                                    </td>
                                </tr>
                            {% endfor %}
                        {% else %}
                            <tr style="margin-left: 1%;">
                                <td id="leimuxuhao1" class="leimuxuhao" style="width: 10%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;">1</td>
                                <td style="width: 40%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;">
                                    <select name="choose_seal" id="AuthorizedSeal1"  style="width: 100%;height: 100%;border: none;outline: none;" onchange="select_seal(1)">
                                        <option value="0" style="text-align: center;">请选择授权印章</option>
                                        {% for seal in seal_obj %}
                                            <option value="{{ seal.id }}" style="text-align: center;">{{ seal.seal_name }}</option>
                                        {% endfor %}
                                    </select>
                                </td>
                                <td class="leimuneirong" style="width: 22.5%;border: #cfcfcf solid 0.5px;text-align: left;height: 35px;line-height: 35px;cursor: pointer;">
                                    <select name="" class="span_tag" id="span_1" style="width: 100%;height: 100%;border: none;outline: none;" onchange="seleect_subject(this.id)">
                                    </select>
                                </td>
                                <td class="shouquan_leval" style="width: 22.5%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;cursor: pointer;">
                                </td>
                                <td style="width: 5%;border: #cfcfcf solid 0.5px;cursor: pointer;text-align: center;">
                                    <span onclick="remove_time_adress(this)" style="color: red; cursor: pointer; display: inline-block;">删除</span>
                                </td>
                            </tr>
                        {% endif %}
                    </table>
                </div>
                <div style="width: 95%;margin-left: 2.5%;">
                    <div style="width: 100%;height: 40px;line-height: 40px;background-color: #dfdfdf;color: #1E90FF;padding-left: 1%;border: #cccccc solid 1px;border-top: none;border-bottom: none;padding-right: 1%;">
                        上传附件
                        <a href="javascript:;" class="file" style="vertical-align: top;margin-top: 5px;float: right;">
                            上传文件
                            <input type="file" name="party_main_body" id="party_main_body"
                                   onchange="upload_accessory('file1', 'party_main', 'party_main_body')">
                        </a>
                    </div>
                    <table style="width: 100%;">
                        <thead>
                        <tr>
                            <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">序号</td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件名称
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                文件大小
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传时间
                            </td>
                            <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                上传人员
                            </td>
                            <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">操作
                            </td>
                        </tr>
                        </thead>
                        <tbody style="overflow: auto;" id="party_main">
                        {% for record in file_list %}
                            <tr>
                                <td style="width: 5%;border: #cccccc solid 1px;text-align: center;">{{ forloop.counter }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.file_name }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.file_size }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.upload_time }}</td>
                                <td style="width: 20%;border: #cccccc solid 1px;border-left: none;text-align: center;">{{ record.uploader }}</td>
                                <td style="width: 15%;border: #cccccc solid 1px;border-left: none;text-align: center;">
                                    <a target='_blank' href="{{ record.file_path }}">查看</a> | <a style="color: red;"
                                                                                                 href='#'
                                                                                                 onclick='RemoveTr(this, "party_main", {{ record.id }})'>删除</a>
                                </td>
                            </tr>
                        {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block script %}
    <script type="text/javascript" src="../../static/public_file/other/jquery.js"></script>
    <script src="../../static/administrative/layDate-v5.0.9/laydate/laydate.js"></script> <!-- 改成你的路径 -->

    <script type="text/javascript">
        window.onload = function () {
            document.getElementById("sponsor").className = "add_class";
            document.getElementById("personage").className = "add-nav-active";
        };

        function select_seal(counts) {
            var quick_obj = {{ quick_obj | safe }};
            var span_id = "span_"+counts;
            var AuthorizedSeal = "AuthorizedSeal"+counts;
            var span_tag = document.getElementById(span_id);
            span_tag.innerHTML = "";
            var seal_id = document.getElementById(AuthorizedSeal).value;
            var leval_list = document.getElementsByClassName("shouquan_leval");
            for (var i=0; i<quick_obj.length; i++) {
                if (String(seal_id) === String(quick_obj[i]["yinzhang"])) {
                    if (quick_obj[i]["neirong"][0]["type"] === '1') {
                        var SubjectText = "一级授权"
                    }else if (quick_obj[i]["neirong"][0]["type"] === '2') {
                        SubjectText = "二级授权"
                    }else {
                        SubjectText = "三级授权"
                    }
                    leval_list[counts-1].innerText = SubjectText;
                    for (var j=0; j<quick_obj[i]["neirong"].length; j++) {
                        var html_str = `
                            <option value="`+quick_obj[i]["neirong"][j]['neirong']+`">`+quick_obj[i]["neirong"][j]['neirong']+`</option>
                        `
                        $("#"+span_id).append(html_str)
                    }

                }
            }
        }

        function seleect_subject(ele_id) {
            var leval_number = ele_id.split("_")[1];
            var subject_obj = {{ quick_obj | safe }};
            var leval_list = document.getElementsByClassName("shouquan_leval");
            var seal_tag_id = "AuthorizedSeal"+leval_number;                        // 选择印章的标签ID
            var seal_id = document.getElementById(seal_tag_id).value;                   // 选取的授权印章id
            var ele_value = document.getElementById(ele_id).value;                      // 选取的授权类目
            for (var i=0; i<subject_obj.length; i++) {
                if (String(seal_id) === String(subject_obj[i]['yinzhang'])) {
                    for (var j=0; j<subject_obj[i]["neirong"].length; j++) {
                        if (subject_obj[i]["neirong"][j]['neirong'] === ele_value) {
                            if (subject_obj[i]["neirong"][j]["type"] === '1') {
                                var SubjectText = "一级授权"
                            }else if (subject_obj[i]["neirong"][j]["type"] === '2') {
                                SubjectText = "二级授权"
                            }else {
                                SubjectText = "三级授权"
                            }
                            leval_list[leval_number-1].innerText = SubjectText;
                            break
                        }
                    }
                }
            }
        }

        function submit_data() {
            var seal_check = document.getElementsByName("choose_seal");
            var leimuxuhao_list = document.getElementsByClassName("leimuxuhao")
            var span_tag_list = document.getElementsByClassName("span_tag")
            var leval_list = document.getElementsByClassName("shouquan_leval")
            var detail_json = []
            for (var i=0; i<seal_check.length; i++) {
                detail_json.push({"xuhao": leimuxuhao_list[i].innerText, "yinzhang": parseInt(seal_check[i].value), 'neirong': span_tag_list[i].value, 'leval': leval_list[i].innerText})
            }

            var authorization_type = document.getElementById("shenqing_type").innerText;
            var take_effect_time = document.getElementById("take_effect_time").innerText;
            var lose_efficacy_time = document.getElementById("lose_efficacy_time").innerText;
            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/finance/QuickAuthorizationIndex.html", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id={{ shortcut_obj.id }}&detail_json=" + JSON.stringify(detail_json)+"&authorization_type="+authorization_type+"&quick_id={{ obj.id }}"+"&lose_efficacy_time="+lose_efficacy_time+"&take_effect_time="+take_effect_time);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("创建成功");
                            window.location = "/finance/QuickAuthorizationList.html";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
             };
        }

        function save_data() {
            var seal_check = document.getElementsByName("choose_seal");
            var leimuxuhao_list = document.getElementsByClassName("leimuxuhao")
            var span_tag_list = document.getElementsByClassName("span_tag")
            var leval_list = document.getElementsByClassName("shouquan_leval")
            var detail_json = []
            for (var i=0; i<seal_check.length; i++) {
                detail_json.push({"xuhao": leimuxuhao_list[i].innerText, "yinzhang": parseInt(seal_check[i].value), 'neirong': span_tag_list[i].value, 'leval': leval_list[i].innerText})
            }

            var authorization_type = document.getElementById("shenqing_type").innerText;
            var take_effect_time = document.getElementById("take_effect_time").innerText;
            var lose_efficacy_time = document.getElementById("lose_efficacy_time").innerText;
            document.getElementById("loading").style.display = "inline-block";
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/finance/QuickAuthorizationDarf.html", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id={{ shortcut_obj.id }}&detail_json=" + JSON.stringify(detail_json)+"&authorization_type="+authorization_type+"&quick_id={{ obj.id }}"+"&lose_efficacy_time="+lose_efficacy_time+"&take_effect_time="+take_effect_time);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        var JsonDate = JSON.parse(xhr.responseText);
                        if (JsonDate["code"] === 200) {
                            alert("保存成功");
                            window.location = "/finance/QuickAuthorizationList.html";
                        } else {
                            alert(JsonDate['message']);
                            document.getElementById("loading").style.display = "none";
                        }
                    }
                }
            };
        }

        function add_other() {
            var leimuxuhao_count =  document.getElementsByClassName("leimuxuhao").length + 1;
            var html = `<tr style="margin-left: 1%;">
                            <td id='leimuxuhao`+String(leimuxuhao_count)+`' class="leimuxuhao" style="width: 10%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;">`+String(leimuxuhao_count)+`</td>
                            <td style="width: 40%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;">
                                <select name="choose_seal" id="AuthorizedSeal`+String(leimuxuhao_count)+`" style="width: 100%;height: 100%;border: none;outline: none;" onchange="select_seal(`+leimuxuhao_count+`)">
                                    <option value="0" style="text-align: center;">请选择授权印章</option>
                                    {% for seal in seal_obj %}
                                        <option value="{{ seal.id }}" style="text-align: center;">{{ seal.seal_name }}</option>
                                    {% endfor %}
                                </select>
                            </td>
                            <td class="leimuneirong" style="width: 22.5%;border: #cfcfcf solid 0.5px;text-align: left;height: 35px;line-height: 35px;cursor: pointer;">
                                <select name="" class="span_tag" id="span_`+String(leimuxuhao_count)+`" style="width: 100%;height: 100%;border: none;outline: none;" onchange="seleect_subject(this.id)">

                                </select>
                            </td>
                            <td class="shouquan_leval" style="width: 22.5%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;cursor: pointer;">
                            </td>
                            <td style="width: 5%;border: #cfcfcf solid 0.5px;text-align: center;height: 35px;line-height: 35px;cursor: pointer;">
                                <span onclick="remove_time_adress(this)" style="color: red; cursor: pointer; display: inline-block;">删除</span>
                            </td>
                        </tr>`
            $("#leimuId").append(html);
        }

        function remove_time_adress(obj) {
            var trNode = $(obj).parent().parent();
            trNode.remove();
            var xuhao_list = document.getElementsByClassName("leimuxuhao");
            for (var i=0; i<xuhao_list.length; i++) {
                xuhao_list[i].innerText=i+1
            }
        }

        // 上传附件
        function upload_accessory(file_type, tbody_id, accessory_type) {
            document.getElementById("loading").style.display = "inline-block";
            var form = new FormData();
            var files = document.getElementById(accessory_type).files[0];
            form.append(file_type, files);
            form.append('number', "{{ shortcut_obj.fj_number }}")
            form.append('source', 'KJYY')
            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/topics_attachments_upload", true);
            xhr.send(form);
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        creat_table(JsonDate, tbody_id)
                    }
                }
            };
        }

        // 创建附件列表
        function creat_table(JsonData, tbody_id) {
            var t_table = document.getElementById(tbody_id);
            var local_host = window.location.host;
            if (Array.isArray(JsonData["pdf_path"])) {
                for (var i = 0; i < JsonData["pdf_path"].length; i++) {
                    var tr = document.createElement("tr");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                    td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                    td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                    td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                    td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                    td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                    td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"][i]["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["pdf_path"][i]["id"] + "\")'>删除</a>";td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                    tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);
                    t_table.appendChild(tr);
                }
                if (JsonData["pdf_path"].length > 1) {
                    document.getElementById("del_adjunct").style.display = 'block';
                }
            } else {
                var tr = document.createElement("tr");var td1 = document.createElement("td");var td2 = document.createElement("td");var td3 = document.createElement("td");var td4 = document.createElement("td");var td5 = document.createElement("td");var td6 = document.createElement("td");
                td1.innerHTML = t_table.children.length + 1;td1.style.textAlign = "center";td1.style.border = "#cccccc solid 1px";td1.style.borderTop = "none";
                td2.innerHTML = JsonData["file_name"];td2.style.paddingLeft = "1%";td2.style.border = "#cccccc solid 1px";td2.style.borderLeft = "none";td2.style.borderTop = "none";
                td3.innerHTML = JsonData["file_size"];td3.style.textAlign = "center";td3.style.border = "#cccccc solid 1px";td3.style.borderLeft = "none";td3.style.borderTop = "none";
                td4.innerHTML = JsonData["upload_time"];td4.style.textAlign = "center";td4.style.border = "#cccccc solid 1px";td4.style.borderLeft = "none";td4.style.borderTop = "none";
                td5.innerHTML = JsonData["uploader"];td5.style.textAlign = "center";td5.style.border = "#cccccc solid 1px";td5.style.borderLeft = "none";td5.style.borderTop = "none";
                td6.innerHTML = "<a target='_blank' href='" + JsonData["pdf_path"] + "'>查看</a> | <a style='color: red;' href='#' onclick='RemoveTr(this, \"" + tbody_id + "\", \"" + JsonData["id"] + "\")'>删除</a>";
                td6.style.textAlign = "center";td6.style.border = "#cccccc solid 1px";td6.style.borderLeft = "none";td6.style.borderTop = "none";
                tr.appendChild(td1);tr.appendChild(td2);tr.appendChild(td3);tr.appendChild(td4);tr.appendChild(td5);tr.appendChild(td6);t_table.appendChild(tr);
            }
        }

        function RemoveTr(_this, tbody_id, wj_id) {
            var table = document.getElementById(tbody_id);
            var trNode = $(_this).parent().parent();
            trNode.remove();

            for (var i = 0; i < table.children.length; i++) {
                table.children[i].children[0].innerHTML = i + 1;
            }

            var xhr = new XMLHttpRequest();
            var local_host = window.location.host;          // 获取当前IP
            xhr.open('post', "/administrative/delete_attachments_view", true);
            xhr.setRequestHeader('content-type', 'application/x-www-form-urlencoded');
            xhr.send("id=" + String(wj_id));
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        document.getElementById("loading").style.display = "none";
                        var JsonDate = JSON.parse(xhr.responseText);
                        console.log(JsonDate);
                        alert("删除成功！")
                    }
                }
            };
        }
    </script>
{% endblock %}